<?php

namespace app\api\model;

use app\basic\BaseModel;

class UserMemberDownloadLog extends BaseModel
{
    protected $name = 'user_member_download_log';

    protected $deleteTime = false;

    /**
     * 获取下载记录列表
     */
    public function getList($userId, $page, $limit)
    {
        return $this->alias('d')
            ->join('eb_article doc', 'doc.id = d.doc_id', 'left')
            ->where('d.user_id', $userId)
            ->field('d.id, d.doc_id, d.title, d.create_time, doc.filesize')
            ->page($page, $limit)
            ->order('d.create_time', 'desc')
            ->select()
            ->toArray();
    }

    /**
     * 获取下载记录总数
     */
    public function getCount($userId)
    {
        return $this->where('user_id', $userId)->count();
    }

    /**
     * 获取指定时间范围内的下载次数
     */
    public function getCountByDate($userId, $startTime, $endTime)
    {
        return $this->where('user_id', $userId)
            ->whereBetween('create_time', [$startTime, $endTime])
            ->count();
    }
} 